package com.cloud.school.app.util;

import io.swagger.annotations.ApiModelProperty;

public class ResponseUtil<T> {

    @ApiModelProperty("请求结果 true或false")
    private boolean result = false;

    @ApiModelProperty("提示信息")
    private String message = "请求失败";

    @ApiModelProperty("响应数据")
    private T data;

    public ResponseUtil(boolean result, String message) {
        this.result = result;
        this.message = message;
    }

    public ResponseUtil(boolean result, String message, T data) {
        this.result = result;
        this.message = message;
        this.data = data;
    }

    public ResponseUtil(T data) {
        this.result = true;
        this.message = "success";
        this.data = data;
    }

    public ResponseUtil() {
        this.result = true;
        this.message = "success";
    }

    public static <T> ResponseUtil<T> ok(T data) {
        return new ResponseUtil(data);
    }

    public static ResponseUtil ok() {
        return new ResponseUtil();
    }

    public static ResponseUtil fail(String message) {
        return new ResponseUtil(false, message);
    }

    public boolean isResult() {
        return result;
    }

    public void setResult(boolean result) {
        this.result = result;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
